﻿#include <iostream>
#include <vector>
#include <QApplication>
#include <QCoreApplication>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>
#include <QFile>
#include "public.h"
#include "Netdisc.h"

int main(int argc, char* argv[]) {
	QApplication a(argc, argv);
	QFile file("register_info.json");
	if (!file.open(QIODevice::ReadWrite)) {
		qDebug() << "register_info.json open error";
		return -1;
	}
	qDebug() << "read register_info.json open!";
	auto content = file.readAll();
	QString key = "foijaoifjewfjoaifmeamfiajejfa";
	auto encodeContent = AESEncode(key, content);
	writeRegisterInfo(encodeContent);

	{
		QFile file("register_info.key");
		if (!file.open(QIODevice::ReadWrite)) {
			qDebug() << "register_info.key open error";
			return false;
		}
		qDebug() << "read register_info.key open!";
		QString key = "foijaoifjewfjoaifmeamfiajejfa";
		auto encodeContent = file.readAll();
		auto content1 = AESDecode(key, encodeContent);
		QJsonParseError errRpt;
		QJsonDocument  rootDoc = QJsonDocument::fromJson(content1.toLatin1(), &errRpt); // 字符串格式化为JSON
		if (errRpt.error != QJsonParseError::NoError)
		{
			qDebug() << "JSON格式错误";
			return false;
		}
	}
	

	//Netdisc netdisc;

	//netdisc.readToken();
	//netdisc.updateToken();
	//QString fileName = "afdsafrewfdsa";
	//QString str("123456493823dfasf47832747fdfdsafdssaf12334324fasfdsf748237481937247324");
	//for (int i = 0; i < 10; ++i) {
	//	auto content = str + QString::number(i);
	//	auto tmpFileName = fileName + QString::number(i) + QString(".txt");
	//	netdisc.uploadFile(tmpFileName, content.toLatin1());
	//}
	
	

	return a.exec();
}